package com.ae.content.web;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class LinuxIdleTime {
    public static long getIdleTimeMillis() {
        try {
            Process process = Runtime.getRuntime().exec("xprintidle");
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = reader.readLine();
            if (line != null) {
                return Long.parseLong(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println("System idle time (ms): " + getIdleTimeMillis());
    }
}

